const db=require('../db/index')
const moment=require('moment')
exports.addArticle=(req,res)=>{
    const articleInfo=req.body
    articleInfo.authorId=req.user.id
    articleInfo.issueData=moment().format('MMMM Do YYYY, h:mm:ss a');
    console.log(articleInfo)
    db.query('insert into article_tab set ?',articleInfo,(err,result)=>{
        if(err){
            return req.resSend(401,err)
        }
        if(result.affectedRows!==1){
            return req.resSend(404,'文章添加失败')
        }
        req.resSend(200,'文章添加成功！')
    })
}

exports.getMyArticles=(req,res)=>{
    db.query('select article_tab.id,title,about,article,tags,issueData,authorId,username,user_pic from article_tab,users where users.id=article_tab.authorId and authorId=?',req.user.id,(err,result)=>{
        if(err){
            return req.resSend(401,err)
        }
        if(result===0){
            return req.resSend(404,'暂无相应数据')
        }
       res.send({
        status:200,
        msg:'数据获取成功',
        data:result
       })
    })
   
   
}